use std::future::Future;
use std::pin::Pin;
use log::Level;
use crate::context::Context;
use crate::message::DynamicMessage;
use crate::errors::SendError;
use crate::middleware::{Middleware, Next};

pub struct LoggingMiddleware {
    log_level: Level,
}

impl LoggingMiddleware {
    pub fn new(log_level: Level) -> Self {
        Self { log_level }
    }
}

impl Middleware for LoggingMiddleware {
    fn handle<'a>(&'a self, ctx: &'a mut Context, msg: DynamicMessage, next: Next<'a>) -> Pin<Box<dyn Future<Output = Result<(), SendError>> + Send + 'a>> {
        Box::pin(async move {
            log::log!(self.log_level, "Processing message: {:?}", msg);
            let result = next().await;
            log::log!(self.log_level, "Message processed with result: {:?}", result);
            result
        })
    }
} 